use std::ops::RangeInclusive;

use egui::Vec2;
use QcUI::component::{Button, Grid};

use crate::inspector::{ComponentState, InspectorContext, InspectorTrait};

impl InspectorTrait for Grid {
    fn inspector(&mut self, ctx: &mut InspectorContext, state: &mut ComponentState) {
        egui::CollapsingHeader::new("Label")
            .default_open(true)
            .show(ctx.ui, |ui| {
                ui.group(|ui| {
                    ui.set_min_width(ui.available_width() - 5.);
                    egui::Grid::new("Label")
                        .num_columns(2)
                        .min_col_width(70.)
                        .spacing(Vec2::new(10., 10.))
                        .show(ui, |ui| {
                            ui.label("列数");
                            ui.add(
                                egui::DragValue::new(&mut self.columns)
                                    .clamp_range(RangeInclusive::new(1, 999))
                                    .speed(0.1),
                            );
                            ui.end_row();

                            ui.label("间隔");

                            let width = ui.available_width() - 10.;
                            egui::Grid::new("Spacing")
                                .num_columns(2)
                                .min_col_width(width / 2.)
                                .spacing(Vec2::new(10., 10.))
                                .show(ui, |ui| {
                                    ui.set_width(width);
                                    ui.horizontal(|ui| {
                                        ui.label("列");
                                        ui.add_space(10.);
                                        ui.add(egui::DragValue::new(&mut self.spacing.x).speed(1));
                                    });
                                    ui.horizontal(|ui| {
                                        ui.label("行");
                                        ui.add_space(10.);
                                        ui.add(egui::DragValue::new(&mut self.spacing.y).speed(1));
                                    });
                                });
                            ui.end_row();
                        })
                });
            });
    }
}
